/*
 **  PTYSession.h
 **
 **  Copyright (c) 2002, 2003
 **
 **  Author: Fabian, Ujwal S. Sathyam
 **
 **  Project: iTerm
 **
 **  Description: Implements the model class for a terminal session.
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License as published by
 **  the Free Software Foundation; either version 2 of the License, or
 **  (at your option) any later version.
 **
 **  This program is distributed in the hope that it will be useful,
 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 **  GNU General Public License for more details.
 **
 **  You should have received a copy of the GNU General Public License
 **  along with this program; if not, write to the Free Software
 **  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@class PTYTask;
@class PTYTextView;
@class VT100Screen;
@class VT100Terminal;
@class ITTerminal;
@class PTYTabViewItem;
@class ITSessionDesc;
@class PTYScrollView;

@interface PTYSession : NSResponder
{
	id				_delegate;
    
	// Owning tab view item
    PTYTabViewItem *_tabViewItem;

    // text storage
    NSTextStorage	*textStorage;
    
    // tab label attributes
    NSDictionary	*normalStateAttribute;
    NSDictionary	*chosenStateAttribute;
    NSDictionary	*idleStateAttribute;
    NSDictionary	*newOutputStateAttribute;
    NSDictionary	*deadStateAttribute;
    
    ITTerminal		*parent;  // parent controller
    NSString		*_name;
    
    // anti-idle
    char ai_code;

    PTYTask			*_shell;
    VT100Terminal	*_terminal;
    VT100Screen		*_screen;    
	PTYScrollView	*_scrollView;
    PTYTextView		*_textView;
    NSString		*TERM_VALUE;
    BOOL EXIT;
    int	_iIdleCount, oIdleCount;
    BOOL dirty;
    BOOL _refreshed;
    BOOL antiIdle;
    BOOL waiting;
    BOOL autoClose;
    BOOL doubleWidth;
    BOOL remapDeleteKey;
    
    BOOL _performDelayedUpdate;
    
    NSTimer			*_timer;
    NSTimer			*_blinkTimer;
}

// init/dealloc
- (id) init;
- (void) dealloc;

- (void)startSession:(NSString*)title blinkCursor:(BOOL)blinkCursor;

// Session specific methods
- (void)initScreen:(NSRect) aRect;
- (void)startProgram:(NSString *)program
	   arguments:(NSArray *)prog_argv
	 environment:(NSDictionary *)prog_env;
- (void) terminate;
- (BOOL) isActiveSession;
- (void) setSizeFromFrame:(NSRect)frame;
- (NSSize) getSizeFromFrame:(NSRect)frame;

// Preferences
- (void)setPreferencesFromSessionDesc:(ITSessionDesc *)desc;

// PTYTask
- (void)readTask:(NSData *)data;
- (void)brokenPipe;
- (NSData *)readData;

// PTYTextView
- (void)keyDown:(NSEvent *)event;
- (BOOL)willHandleEvent: (NSEvent *) theEvent;
- (void)handleEvent: (NSEvent *) theEvent;
- (void)insertText:(NSString *)string;
- (void)insertNewline:(id)sender;
- (void)insertTab:(id)sender;
- (void)moveUp:(id)sender;
- (void)moveDown:(id)sender;
- (void)moveLeft:(id)sender;
- (void)moveRight:(id)sender;
- (void)pageUp:(id)sender;
- (void)pageDown:(id)sender;
- (void)paste:(id)sender;
- (void)pasteString:(NSString *)aString;
- (void)deleteBackward:(id)sender;
- (void)deleteForward:(id)sender;
- (void)scrollViewResized:(PTYScrollView *)scrollView;

// misc
- (void) handleOptionClick: (NSEvent *) theEvent;

// get/set methods
- (ITTerminal *)		parent;
- (PTYTabViewItem *)	tabViewItem;
- (NSString *)			name;
- (NSString *)			uniqueID;
- (PTYTask *)			shell;
- (VT100Terminal *)		TERMINAL;
- (VT100Screen *)		SCREEN;
- (PTYTextView *)		TEXTVIEW;
- (NSScrollView *)		scrollView;
- (NSString *)			TERM_VALUE;
- (void) setParent:		(ITTerminal *) theParent;
- (void) setName: (NSString *) theName;
- (void) setUniqueID: (NSString *)uniqueID;
- (void) setTabViewItem: (PTYTabViewItem *) theTabViewItem;
- (void) setTERMINAL: (VT100Terminal *) theTERMINAL;
- (void)	setSHELL: (PTYTask *) theSHELL;
- (void) setTERM_VALUE: (NSString *) theTERM_VALUE;
- (void) setSCREEN: (VT100Screen *) theSCREEN;
- (void)setEncoding:(NSStringEncoding)encoding;
- (BOOL) antiIdle;
- (int) antiCode;
- (void) setAntiIdle:(BOOL)set;
- (void) setAntiCode:(int)code;
- (BOOL) autoClose;
- (void) setAutoClose:(BOOL)set;
- (BOOL) doubleWidth;
- (void) setDoubleWidth:(BOOL)set;
- (int) number;
- (NSString *) tty;
- (BOOL) remapDeleteKey;
- (void) setRemapDeleteKey: (BOOL) flag;

- (void)clearBuffer;
- (void)clearScrollbackBuffer;
- (void)logStart;
- (void)logStop;
- (NSColor *) foregroundColor;
- (void)setForegroundColor:(NSColor*) color;
- (NSColor *) backgroundColor;
- (void)setBackgroundColor:(NSColor*) color;
- (NSColor *) selectionColor;
- (void) setSelectionColor: (NSColor *) color;
- (NSColor *) boldColor;
- (void)setBoldColor:(NSColor*) color;
- (float) transparency;
- (void)setTransparency:(float)transparency;
- (void) setColorTable:(int) index highLight:(BOOL)hili color:(NSColor *) c;
- (NSTextStorage *) textStorage;

- (void)setDelegate:(id)object;
- (id)delegate;

// Session status

- (void)resetStatus;
- (BOOL)exited;
- (void)setBell;
- (void)setBell: (BOOL) flag;
- (void)setLabelAttribute;

@end
